package com.jc.oms.controller.product.productType;

import com.jc.common.util.WebUtils;
import com.jc.service.producttype.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("productType")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;


    /**
     * 保存商城分类时同时新增OMS的分类(编辑)
     */
    @PostMapping("addOMSProductType")
    public Map<String, Object> addOMSProductType(HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = new HashMap<>();

        try {
            params = WebUtils.ReadAsChars(request);
            if (params == null) {
                result.put("code", 6666);
                result.put("data", "OMS接收参数为空");
                result.put("msg", "OMS接收参数为空");
                return result;
            }

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return this.productTypeService.addOMSProductType(params);
    }

    /**
     * 删除商城分类时同时 删除OMS的分类
     */
    @PostMapping("delOMSProductType")
    public Map<String, Object> delOMSProductType(HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = new HashMap<>();

        try {
            params = WebUtils.ReadAsChars(request);
            if (params == null) {
                result.put("code", 6666);
                result.put("data", "OMS接收参数为空!");
                result.put("msg", "OMS接收参数为空!");
                return result;
            }

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return this.productTypeService.delOMSProductType(params);
    }


}
